
package brickbreaker;

import javafx.scene.Parent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

class Brick extends Parent {

    private static final int TYPE_BLUE = 0;
    private static final int TYPE_BROKEN1 = 1;
    private static final int TYPE_BROKEN2 = 2;
    private static final int TYPE_BROWN = 3;
    private static final int TYPE_CYAN = 4;
    private static final int TYPE_GREEN = 5;
    static final int TYPE_GREY = 6;
    private static final int TYPE_MAGENTA = 7;
    private static final int TYPE_ORANGE = 8;
    private static final int TYPE_RED = 9;
    private static final int TYPE_VIOLET = 10;
    private static final int TYPE_WHITE = 11;
    private static final int TYPE_YELLOW = 12;

    private int type;
    private ImageView content;

    Brick(int type) {
        content = new ImageView();
        getChildren().add(content);
        changeType(type);
        setMouseTransparent(true);
    }

    int getType() {
        return type;
    }

    boolean kick() {
        if (type == TYPE_GREY) {
            return false;
        }
        if (type == TYPE_BROKEN1) {
            changeType(TYPE_BROKEN2);
            return false;
        }
        return true;
    }

    private void changeType(int newType) {
        this.type = newType;
        Image image = Config.getBricksImages().get(type);
        content.setImage(image);
        content.setFitWidth(Config.FIELD_WIDTH/15);
    }

    

    static int getBrickType(String s) {
        switch (s) {
            case "L":
                return TYPE_BLUE;
            case "2":
                return TYPE_BROKEN1;
            case "B":
                return TYPE_BROWN;
            case "C":
                return TYPE_CYAN;
            case "G":
                return TYPE_GREEN;
            case "0":
                return TYPE_GREY;
            case "M":
                return TYPE_MAGENTA;
            case "O":
                return TYPE_ORANGE;
            case "R":
                return TYPE_RED;
            case "V":
                return TYPE_VIOLET;
            case "W":
                return TYPE_WHITE;
            case "Y":
                return TYPE_YELLOW;
        }
        System.out.println("Unknown brick type '{s}'");
        return TYPE_WHITE;
    }

}


